package usian.hx.login.lister;


import cn.hutool.core.util.RandomUtil;
import com.usian.third.code.AliCodeUtils;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.messaging.Message;

import java.util.concurrent.TimeUnit;

public class RabbitLister {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @RabbitListener(queues = "java-queue")
    public void sendLoginCode(Message message,String phone) throws Exception {

        AliCodeUtils aliCodeUtils=new AliCodeUtils();

        String code=RandomUtil.randomNumbers(6);

        aliCodeUtils.sendLoginCode(phone,code);
        stringRedisTemplate.opsForValue().set(code,phone);
        stringRedisTemplate.expire(phone,5, TimeUnit.MINUTES);
        System.out.println("监听到有消息产生");

    }

}
